<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: CSMAMacLayer Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00069.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="#pri-methods">Private Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">CSMAMacLayer Class Reference<div class="ingroups"><a class="el" href="a00509.html">macLayer - MAC layer modules</a> &#124; <a class="el" href="a00525.html">CSMA - Classes for the CSMA implementation of MiXiM</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="CSMAMacLayer" --><!-- doxytag: inherits="BaseMacLayer" -->
<p>MAC module which provides non-persistent CSMA.  
 <a href="a00069.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="a00430_source.html">CSMAMacLayer.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for CSMAMacLayer:</div>
<div class="dyncontent">
<div class="center"><img src="a00688.png" border="0" usemap="#CSMAMacLayer_inherit__map" alt="Inheritance graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for CSMAMacLayer:</div>
<div class="dyncontent">
<div class="center"><img src="a00689.png" border="0" usemap="#CSMAMacLayer_coll__map" alt="Collaboration graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>

<p><a href="a00690.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pro-types"></a>
Protected Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913">States</a> { <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631">RX</a>, 
<a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca">CCA</a>, 
<a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0">TX</a>
 }</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">MAC states.  <a href="a00069.html#aa504ef94f12cc702c82a81f5f0654913">More...</a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="af397ee30d94486721632bbcdad8274d1"></a><!-- doxytag: member="CSMAMacLayer::MacQueue" ref="af397ee30d94486721632bbcdad8274d1" args="" -->
typedef std::list&lt; cPacket * &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#af397ee30d94486721632bbcdad8274d1">MacQueue</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Type for a queue of cPackets. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a660262c629f33b00401249d3fdac49be">initialize</a> (int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Inspect reasons for dropped packets.  <a href="#a660262c629f33b00401249d3fdac49be"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aeaffa0655b4e87224a9a2f09b96805d7"></a><!-- doxytag: member="CSMAMacLayer::finish" ref="aeaffa0655b4e87224a9a2f09b96805d7" args="()" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#aeaffa0655b4e87224a9a2f09b96805d7">finish</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Delete all dynamically allocated objects of the module. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a83911b5673de047bcfc3c9b0a719ff15">handleLowerMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle messages from lower layer.  <a href="#a83911b5673de047bcfc3c9b0a719ff15"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a06c96c060afdff5c0f348b5ebef5c54d">handleUpperMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle messages from upper layer.  <a href="#a06c96c060afdff5c0f348b5ebef5c54d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a254a29c1cc1f0292039d57c1d189cda3">handleSelfMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle self messages such as timers.  <a href="#a254a29c1cc1f0292039d57c1d189cda3"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2eb12cedf0b4b5e6fda8bd6666186cb6"></a><!-- doxytag: member="CSMAMacLayer::handleLowerControl" ref="a2eb12cedf0b4b5e6fda8bd6666186cb6" args="(cMessage *msg)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a2eb12cedf0b4b5e6fda8bd6666186cb6">handleLowerControl</a> (cMessage *msg)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle control messages from lower layer. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">schedule a backoff  <a href="#aa4ace66cbd53164dc27f4fba70dd60b4"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a89de5fd0b7f0d1420c1d4e9118c00ef3"></a><!-- doxytag: member="CSMAMacLayer::encapsMsg" ref="a89de5fd0b7f0d1420c1d4e9118c00ef3" args="(cPacket *pkt)" -->
virtual macpkt_ptr_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3">encapsMsg</a> (cPacket *pkt)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Encapsulates the NetwPkt into the MacPkt and sets the parameters. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa78817d8e3bbf7850e5d84a6377ea907"></a><!-- doxytag: member="CSMAMacLayer::macState" ref="aa78817d8e3bbf7850e5d84a6377ea907" args="" -->
<a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913">States</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907">macState</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">kepp track of MAC state <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a420bec99b62f029c75996930bc5cb56f">slotDuration</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Duration of a slot.  <a href="#a420bec99b62f029c75996930bc5cb56f"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a5a0fde63ac12cccfdb98bfe6314ce46d">difs</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Maximum time between a packet and its ACK.  <a href="#a5a0fde63ac12cccfdb98bfe6314ce46d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a9869bd7667eacdb3a9c5f8ecb0c3ed19"></a><!-- doxytag: member="CSMAMacLayer::macQueue" ref="a9869bd7667eacdb3a9c5f8ecb0c3ed19" args="" -->
<a class="el" href="a00069.html#af397ee30d94486721632bbcdad8274d1">MacQueue</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19">macQueue</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">A queue to store packets from upper layer in case another packet is still waiting for transmission.. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a27628021750dc0e8cf651382663276b8"></a><!-- doxytag: member="CSMAMacLayer::queueLength" ref="a27628021750dc0e8cf651382663276b8" args="" -->
unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a27628021750dc0e8cf651382663276b8">queueLength</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">length of the queue <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a946e29bb8fead33566797a7062649a1e"></a><!-- doxytag: member="CSMAMacLayer::backoffTimer" ref="a946e29bb8fead33566797a7062649a1e" args="" -->
cMessage *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a946e29bb8fead33566797a7062649a1e">backoffTimer</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Timer for backoff (non-persistent CSMA) <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">cMessage *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#af06855c96a26dbe77937062bead7f82c">minorMsg</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Multi-purpose message.  <a href="#af06855c96a26dbe77937062bead7f82c"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b">txAttempts</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">count the number of tx attempts  <a href="#a6c9b1b0f5eeb45db611633ca986f537b"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#ae3aa6dae3903cabacbcafe783ef33d91">maxTxAttempts</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">maximum number of transmission attempts  <a href="#ae3aa6dae3903cabacbcafe783ef33d91"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a70ae938b76fa8fe65d97b0b511767894"></a><!-- doxytag: member="CSMAMacLayer::bitrate" ref="a70ae938b76fa8fe65d97b0b511767894" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a70ae938b76fa8fe65d97b0b511767894">bitrate</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">the bit rate at which we transmit <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a619cc05568e8ebef57ff9c551cd311d0"></a><!-- doxytag: member="CSMAMacLayer::txPower" ref="a619cc05568e8ebef57ff9c551cd311d0" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a619cc05568e8ebef57ff9c551cd311d0">txPower</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">The power at which we transmit. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8ec2aea0983e2149d3c7d1c06637dd70"></a><!-- doxytag: member="CSMAMacLayer::initialCW" ref="a8ec2aea0983e2149d3c7d1c06637dd70" args="" -->
unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a8ec2aea0983e2149d3c7d1c06637dd70">initialCW</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">initial contention window size <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae768a2dadff7e2e41a5ecae37bcedc2d"></a><!-- doxytag: member="CSMAMacLayer::nbBackoffs" ref="ae768a2dadff7e2e41a5ecae37bcedc2d" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#ae768a2dadff7e2e41a5ecae37bcedc2d">nbBackoffs</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Counts the total number of backoffs. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ace6a061501b4d12d2380a458ea253ef5"></a><!-- doxytag: member="CSMAMacLayer::backoffValues" ref="ace6a061501b4d12d2380a458ea253ef5" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#ace6a061501b4d12d2380a458ea253ef5">backoffValues</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Counts the total time spent in backoff. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a4e15b3f78a53218321cbc408f1cb600b"></a><!-- doxytag: member="CSMAMacLayer::nbTxFrames" ref="a4e15b3f78a53218321cbc408f1cb600b" args="" -->
unsigned long&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a4e15b3f78a53218321cbc408f1cb600b">nbTxFrames</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Counts the number of frames transmitted. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pri-methods"></a>
Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a00a8c8316ff1b37292d80b7ae4e3cb1c"></a><!-- doxytag: member="CSMAMacLayer::CSMAMacLayer" ref="a00a8c8316ff1b37292d80b7ae4e3cb1c" args="(const CSMAMacLayer &amp;)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a00a8c8316ff1b37292d80b7ae4e3cb1c">CSMAMacLayer</a> (const <a class="el" href="a00069.html">CSMAMacLayer</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Copy constructor is not allowed. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5e45c114db302a9337ea13ca378cd98a"></a><!-- doxytag: member="CSMAMacLayer::operator=" ref="a5e45c114db302a9337ea13ca378cd98a" args="(const CSMAMacLayer &amp;)" -->
<a class="el" href="a00069.html">CSMAMacLayer</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00069.html#a5e45c114db302a9337ea13ca378cd98a">operator=</a> (const <a class="el" href="a00069.html">CSMAMacLayer</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Assignment operator is not allowed. <br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>MAC module which provides non-persistent CSMA. </p>
<p>This is an implementation of a simple non-persistent CSMA. The idea of nonpersistent CSMA is "listen before talk". Before attempting to transmit, a station will sense the medium for a carrier signal, which, if present, indicates that some other station is sending.</p>
<p>If the channel is busy a random waiting time is computed and after this time the channel is sensed again. Once the channel gets idle the message is sent. (State of the channel is obtained from <a class="el" href="a00043.html" title="This class is used by the BasePhyLayer to keep track of the AirFrames on the channel.">ChannelInfo</a> via phyLayer.)</p>
<p>An option of this module is to use a queue. If a packet from the upper layer arrives although there is still another packet waiting for its transmission or being transmitted the new packet can be stored in this queue. The length of this queue can be specified by the user in the omnetpp.ini file. By default the length is 0. If the queue is full or there is no queue (length = 0) new packet(s) will be deleted.</p>
<p>ATTENTION: Imagine the following scenario:</p>
<p>Several stations receive a broadcast request packet, usally exactly at the same time. They will all try to answer at exactly the same time, i.e. they all will sense the channel at exactly the same time and start to transmit because the channel was sensed idle by all of them. Therefore a small random delay should be built into one/some of the upper layers to simulate a random processing time!</p>
<p>The <a class="el" href="a00208.html" title="Test class for the application layer.">TestApplLayer</a> e.g. implements such a processing delay!</p>
<dl class="author"><dt><b>Author:</b></dt><dd>Marc L�bbers, Yosia Hadisusanto, Andreas Koepke, Karl Wessel </dd></dl>
</div><hr/><h2>Member Enumeration Documentation</h2>
<a class="anchor" id="aa504ef94f12cc702c82a81f5f0654913"></a><!-- doxytag: member="CSMAMacLayer::States" ref="aa504ef94f12cc702c82a81f5f0654913" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913">CSMAMacLayer::States</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>MAC states. </p>
<p>The MAC states help to keep track what the MAC is actually trying to do -- this is esp. useful when radio switching takes some time. </p>
<dl><dt><b>Enumerator: </b></dt><dd><table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><em><a class="anchor" id="aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631"></a><!-- doxytag: member="RX" ref="aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" args="" -->RX</em>&nbsp;</td><td>
<p>MAC accepts packets from PHY layer. </p>
</td></tr>
<tr><td valign="top"><em><a class="anchor" id="aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca"></a><!-- doxytag: member="CCA" ref="aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca" args="" -->CCA</em>&nbsp;</td><td>
<p>Clear Channel Assessment - MAC checks whether medium is busy. </p>
</td></tr>
<tr><td valign="top"><em><a class="anchor" id="aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0"></a><!-- doxytag: member="TX" ref="aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0" args="" -->TX</em>&nbsp;</td><td>
<p>MAC transmits a packet. </p>
</td></tr>
</table>
</dd>
</dl>
<div class="fragment"><pre class="fragment">                {
        <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>,
        <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca" title="Clear Channel Assessment - MAC checks whether medium is busy.">CCA</a>,
        <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0" title="MAC transmits a packet.">TX</a>,
    };
</pre></div>
</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a83911b5673de047bcfc3c9b0a719ff15"></a><!-- doxytag: member="CSMAMacLayer::handleLowerMsg" ref="a83911b5673de047bcfc3c9b0a719ff15" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void CSMAMacLayer::handleLowerMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle messages from lower layer. </p>
<p>Compare the address of this Host with the destination address in frame. If they are equal or the frame is broadcast, we send this frame to the upper layer. If not delete it. </p>

<p>Reimplemented from <a class="el" href="a00026.html#a413375cec02b990a521b62086a02264c">BaseMacLayer</a>.</p>

<p>References <a class="el" href="a00069.html#a946e29bb8fead33566797a7062649a1e">backoffTimer</a>, <a class="el" href="a00026.html#a998b4c4c56074a354b50f8c4fc5d6d4c">BaseMacLayer::decapsMsg()</a>, <a class="el" href="a00117.html#a3890f1c7314c5695e32252468e6bd5a5">LAddress::isL2Broadcast()</a>, <a class="el" href="a00026.html#a8a26df9da07801d8ccb530530ef57ee2">BaseMacLayer::myMacAddr</a>, <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>, and <a class="el" href="a00025.html#adbf061566606041db811b519f0400ed5">BaseLayer::sendUp()</a>.</p>
<div class="fragment"><pre class="fragment">{
    macpkt_ptr_t            mac  = <span class="keyword">static_cast&lt;</span>macpkt_ptr_t<span class="keyword">&gt;</span>(msg);
    <span class="keyword">const</span> <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a>&amp; dest = mac-&gt;getDestAddr();

    <span class="keywordflow">if</span>(dest == <a class="code" href="a00026.html#a8a26df9da07801d8ccb530530ef57ee2" title="MAC address.">myMacAddr</a> || <a class="code" href="a00117.html#a3890f1c7314c5695e32252468e6bd5a5" title="Test if a L2 address (pSrcAddr) is a broadcast address.">LAddress::isL2Broadcast</a>(dest))
    {
      debugEV &lt;&lt; <span class="stringliteral">&quot;sending pkt to upper...\n&quot;</span>;
        <a class="code" href="a00025.html#adbf061566606041db811b519f0400ed5" title="Sends a message to the upper layer.">sendUp</a>(<a class="code" href="a00026.html#a998b4c4c56074a354b50f8c4fc5d6d4c" title="decapsulate the network message from the MacPkt">decapsMsg</a>(mac));
    }
    <span class="keywordflow">else</span> {
      debugEV &lt;&lt; <span class="stringliteral">&quot;packet not for me, deleting...\n&quot;</span>;
        <span class="keyword">delete</span> mac;
    }

    <span class="keywordflow">if</span>(!<a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>-&gt;isScheduled()) <a class="code" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4" title="schedule a backoff">scheduleBackoff</a>();
}
</pre></div>
</div>
</div>
<a class="anchor" id="a254a29c1cc1f0292039d57c1d189cda3"></a><!-- doxytag: member="CSMAMacLayer::handleSelfMsg" ref="a254a29c1cc1f0292039d57c1d189cda3" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void CSMAMacLayer::handleSelfMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle self messages such as timers. </p>
<p>After the timer expires try to retransmit the message by calling handleUpperMsg again. </p>

<p>Reimplemented from <a class="el" href="a00026.html#add5277c1a60dab10db40c8d9641e48c4">BaseMacLayer</a>.</p>

<p>References <a class="el" href="a00069.html#a946e29bb8fead33566797a7062649a1e">backoffTimer</a>, <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca">CCA</a>, <a class="el" href="a00069.html#a5a0fde63ac12cccfdb98bfe6314ce46d">difs</a>, <a class="el" href="a00134.html#affa30a25b96ffe387b22c68ca35f77a5">MacToPhyInterface::getChannelState()</a>, <a class="el" href="a00134.html#a00dd43576b4da205117d53bd3baadc71">MacToPhyInterface::getRadioState()</a>, <a class="el" href="a00044.html#ab09e4515d5428b1287a62ec1bd1b01fe">ChannelState::isIdle()</a>, <a class="el" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19">macQueue</a>, <a class="el" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907">macState</a>, <a class="el" href="a00069.html#af06855c96a26dbe77937062bead7f82c">minorMsg</a>, <a class="el" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea">BaseMacLayer::phy</a>, <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631">RX</a>, <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>, <a class="el" href="a00134.html#ad25abbad9aa16bdbf24bf1dd582b1c6f">MacToPhyInterface::setRadioState()</a>, <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0">TX</a>, and <a class="el" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a4f6c3dfae0f5fccb76b1d42f6ccc785d">MiximRadio::TX</a>.</p>
<div class="fragment"><pre class="fragment">{
    <span class="keywordflow">if</span>(msg == <a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>) {
      debugEV &lt;&lt; <span class="stringliteral">&quot;backoffTimer &quot;</span>;

        <span class="keywordflow">if</span>(<a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> == <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>) {
          debugEV &lt;&lt; <span class="stringliteral">&quot; RX &quot;</span>;

            <span class="keywordflow">if</span>(<a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.size() != 0) {
              <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> = <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca" title="Clear Channel Assessment - MAC checks whether medium is busy.">CCA</a>;

                <span class="keywordflow">if</span>(<a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#a00dd43576b4da205117d53bd3baadc71" title="Returns the current state the radio is in. See RadioState for possible values.">getRadioState</a>() == <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">MiximRadio::RX</a>) {

                    <span class="keywordflow">if</span>(<a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#affa30a25b96ffe387b22c68ca35f77a5" title="Returns the current state of the channel. See ChannelState for details.">getChannelState</a>().<a class="code" href="a00044.html#ab09e4515d5428b1287a62ec1bd1b01fe" title="Returns true if the channel is considered idle, meaning depends on the used decider.">isIdle</a>()) {
                      debugEV &lt;&lt; <span class="stringliteral">&quot; idle &quot;</span>;
                        scheduleAt(simTime()+<a class="code" href="a00069.html#a5a0fde63ac12cccfdb98bfe6314ce46d" title="Maximum time between a packet and its ACK.">difs</a>, <a class="code" href="a00069.html#af06855c96a26dbe77937062bead7f82c" title="Multi-purpose message.">minorMsg</a>);
                    }
                    <span class="keywordflow">else</span> {
                      <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> = <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>;
                      debugEV &lt;&lt; <span class="stringliteral">&quot; busy &quot;</span>;
                        <a class="code" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4" title="schedule a backoff">scheduleBackoff</a>();
                    }
                }
            }
        }
        <span class="keywordflow">else</span> {
          debugEV &lt;&lt; <span class="stringliteral">&quot;&quot;</span> &lt;&lt; endl;
          debugEV &lt;&lt; <span class="stringliteral">&quot;state=&quot;</span> &lt;&lt; <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> &lt;&lt; <span class="stringliteral">&quot;(TX=&quot;</span>&lt;&lt;<a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0" title="MAC transmits a packet.">TX</a>&lt;&lt;<span class="stringliteral">&quot;, CCA=&quot;</span>&lt;&lt;<a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca" title="Clear Channel Assessment - MAC checks whether medium is busy.">CCA</a>&lt;&lt;<span class="stringliteral">&quot;)\n&quot;</span>;
            error(<span class="stringliteral">&quot;backoffTimer expired, MAC in wrong state&quot;</span>);
        }
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(msg == <a class="code" href="a00069.html#af06855c96a26dbe77937062bead7f82c" title="Multi-purpose message.">minorMsg</a>) {
      debugEV &lt;&lt; <span class="stringliteral">&quot; minorMsg &quot;</span>;

        <span class="comment">//TODO: replace with channel sense request</span>
        <span class="keywordflow">if</span>((<a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> == <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913acd80830b40d6cc8615ea4ff537cb37ca" title="Clear Channel Assessment - MAC checks whether medium is busy.">CCA</a>) &amp;&amp; (<a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#a00dd43576b4da205117d53bd3baadc71" title="Returns the current state the radio is in. See RadioState for possible values.">getRadioState</a>() == <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">MiximRadio::RX</a>)) {

            <span class="keywordflow">if</span>(<a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#affa30a25b96ffe387b22c68ca35f77a5" title="Returns the current state of the channel. See ChannelState for details.">getChannelState</a>().<a class="code" href="a00044.html#ab09e4515d5428b1287a62ec1bd1b01fe" title="Returns true if the channel is considered idle, meaning depends on the used decider.">isIdle</a>()) {
              debugEV &lt;&lt; <span class="stringliteral">&quot; idle -&gt; to send &quot;</span>;
                <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> = <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913a18461bd2358689c90c3c5cade629e0b0" title="MAC transmits a packet.">TX</a>;
                <a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#ad25abbad9aa16bdbf24bf1dd582b1c6f" title="Tells the BasePhyLayer to switch to the specified radio state.">setRadioState</a>(<a class="code" href="a00141.html#a5d69aacb1cf6a57827f07224219fccb7a4f6c3dfae0f5fccb76b1d42f6ccc785d" title="transmitting state">MiximRadio::TX</a>);
            }
            <span class="keywordflow">else</span> {
              debugEV &lt;&lt; <span class="stringliteral">&quot; busy -&gt; backoff &quot;</span>;
                <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> = <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>;
                <span class="keywordflow">if</span>(!<a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>-&gt;isScheduled())
                  <a class="code" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4" title="schedule a backoff">scheduleBackoff</a>();
            }
        }
        <span class="keywordflow">else</span> {
            error(<span class="stringliteral">&quot;minClearTimer fired -- channel or mac in wrong state&quot;</span>);
        }
    }
    debugEV &lt;&lt; endl;
}
</pre></div>
</div>
</div>
<a class="anchor" id="a06c96c060afdff5c0f348b5ebef5c54d"></a><!-- doxytag: member="CSMAMacLayer::handleUpperMsg" ref="a06c96c060afdff5c0f348b5ebef5c54d" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void CSMAMacLayer::handleUpperMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle messages from upper layer. </p>
<p>First it has to be checked whether a frame is currently being transmitted or waiting to be transmitted. If so the newly arrived message is stored in a queue. If there is no queue or it is full print a warning.</p>
<p>Before transmitting a frame it is tested whether the channel is busy at the moment or not. If the channel is busy, a short random time will be generated and the MacPkt is buffered for this time, before a next attempt to send the packet is started.</p>
<p>If channel is idle the frame will be transmitted immediately. </p>

<p>Reimplemented from <a class="el" href="a00026.html#a6de2ca07018de313a7147a03e6d77bff">BaseMacLayer</a>.</p>

<p>References <a class="el" href="a00069.html#a946e29bb8fead33566797a7062649a1e">backoffTimer</a>, <a class="el" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3">encapsMsg()</a>, <a class="el" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19">macQueue</a>, <a class="el" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907">macState</a>, <a class="el" href="a00026.html#a49e0e548a6c20d002bd67afa7b76c483adebf9c77bbe6f19772866cccbef0fe4b">BaseMacLayer::PACKET_DROPPED</a>, <a class="el" href="a00069.html#a27628021750dc0e8cf651382663276b8">queueLength</a>, <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631">RX</a>, <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>, and <a class="el" href="a00025.html#aa1190a06fb4dfb15d8ff001468335dc8">BaseLayer::sendControlUp()</a>.</p>
<div class="fragment"><pre class="fragment">{
  cPacket* pkt = <span class="keyword">static_cast&lt;</span>cPacket*<span class="keyword">&gt;</span>(msg);

    <span class="comment">//MacPkt *mac = encapsMsg(pkt);</span>

    <span class="comment">// message has to be queued if another message is waiting to be send</span>
    <span class="comment">// or if we are already trying to send another message</span>

    <span class="keywordflow">if</span> (<a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.size() &lt;= <a class="code" href="a00069.html#a27628021750dc0e8cf651382663276b8" title="length of the queue">queueLength</a>)
    {
        <a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.push_back(pkt);
        debugEV   &lt;&lt; <span class="stringliteral">&quot;packet putt in queue\n  queue size:&quot;</span> &lt;&lt; <a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.size() &lt;&lt; <span class="stringliteral">&quot; macState:&quot;</span> &lt;&lt; <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a>
      &lt;&lt; <span class="stringliteral">&quot; (RX=&quot;</span> &lt;&lt; <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a> &lt;&lt; <span class="stringliteral">&quot;) is scheduled:&quot;</span> &lt;&lt; <a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>-&gt;isScheduled() &lt;&lt; endl;;

        <span class="keywordflow">if</span>((<a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.size() == 1) &amp;&amp; (<a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> == <a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>) &amp;&amp; !<a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>-&gt;isScheduled()) {
            <a class="code" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4" title="schedule a backoff">scheduleBackoff</a>();
        }
    }
    <span class="keywordflow">else</span> {
        <span class="comment">// queue is full, message has to be deleted</span>
      EV &lt;&lt; <span class="stringliteral">&quot;New packet arrived, but queue is FULL, so new packet is deleted\n&quot;</span>;
      macpkt_ptr_t mac = <a class="code" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3" title="Encapsulates the NetwPkt into the MacPkt and sets the parameters.">encapsMsg</a>(pkt);
        mac-&gt;setName(<span class="stringliteral">&quot;MAC ERROR&quot;</span>);
        mac-&gt;setKind(<a class="code" href="a00026.html#a49e0e548a6c20d002bd67afa7b76c483adebf9c77bbe6f19772866cccbef0fe4b">PACKET_DROPPED</a>);
        <a class="code" href="a00025.html#aa1190a06fb4dfb15d8ff001468335dc8" title="Sends a control message to an upper layer.">sendControlUp</a>(mac);

        <span class="comment">//TODO: send packet drop bb info</span>
        <span class="comment">//droppedPacket.setReason(DroppedPacket::QUEUE);</span>
        <span class="comment">//emitItem(catDroppedPacket, &amp;droppedPacket);</span>
    }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a660262c629f33b00401249d3fdac49be"></a><!-- doxytag: member="CSMAMacLayer::initialize" ref="a660262c629f33b00401249d3fdac49be" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">virtual void CSMAMacLayer::initialize </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Inspect reasons for dropped packets. </p>
<p>plus category from BB publish dropped packets nic wide Initialization of the module and some variables </p>

<p>Reimplemented from <a class="el" href="a00026.html#a61c82dc3b225eac37f7fa9936c28c2c3">BaseMacLayer</a>.</p>

</div>
</div>
<a class="anchor" id="aa4ace66cbd53164dc27f4fba70dd60b4"></a><!-- doxytag: member="CSMAMacLayer::scheduleBackoff" ref="aa4ace66cbd53164dc27f4fba70dd60b4" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void CSMAMacLayer::scheduleBackoff </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>schedule a backoff </p>
<p>A non-persistent CSMA ideally uses a fixed backoff window, but it could also increase this window in a linear fashion, or even exponential -- here, a linear increase is used. Overwrite this function to define another schedule function. It also checks the retransmission counters -- if you overwrite it, do it with care. </p>

<p>References <a class="el" href="a00069.html#a946e29bb8fead33566797a7062649a1e">backoffTimer</a>, <a class="el" href="a00069.html#ace6a061501b4d12d2380a458ea253ef5">backoffValues</a>, <a class="el" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3">encapsMsg()</a>, <a class="el" href="a00134.html#a00dd43576b4da205117d53bd3baadc71">MacToPhyInterface::getRadioState()</a>, <a class="el" href="a00069.html#a8ec2aea0983e2149d3c7d1c06637dd70">initialCW</a>, <a class="el" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19">macQueue</a>, <a class="el" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907">macState</a>, <a class="el" href="a00069.html#ae3aa6dae3903cabacbcafe783ef33d91">maxTxAttempts</a>, <a class="el" href="a00069.html#af06855c96a26dbe77937062bead7f82c">minorMsg</a>, <a class="el" href="a00069.html#ae768a2dadff7e2e41a5ecae37bcedc2d">nbBackoffs</a>, <a class="el" href="a00026.html#a49e0e548a6c20d002bd67afa7b76c483adebf9c77bbe6f19772866cccbef0fe4b">BaseMacLayer::PACKET_DROPPED</a>, <a class="el" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea">BaseMacLayer::phy</a>, <a class="el" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631">RX</a>, <a class="el" href="a00025.html#aa1190a06fb4dfb15d8ff001468335dc8">BaseLayer::sendControlUp()</a>, <a class="el" href="a00069.html#a420bec99b62f029c75996930bc5cb56f">slotDuration</a>, and <a class="el" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b">txAttempts</a>.</p>

<p>Referenced by <a class="el" href="a00069.html#a2eb12cedf0b4b5e6fda8bd6666186cb6">handleLowerControl()</a>, <a class="el" href="a00069.html#a83911b5673de047bcfc3c9b0a719ff15">handleLowerMsg()</a>, <a class="el" href="a00069.html#a254a29c1cc1f0292039d57c1d189cda3">handleSelfMsg()</a>, and <a class="el" href="a00069.html#a06c96c060afdff5c0f348b5ebef5c54d">handleUpperMsg()</a>.</p>
<div class="fragment"><pre class="fragment">{
    <span class="keywordflow">if</span>(<a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>-&gt;isScheduled()) {
        std::cerr &lt;&lt; <span class="stringliteral">&quot; is scheduled: MAC state &quot;</span>
                  &lt;&lt; <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a> &lt;&lt; <span class="stringliteral">&quot; radio state : &quot;</span> &lt;&lt; <a class="code" href="a00026.html#aa7b1e6bdb734765a9f4eff7d486dfbea" title="Handler to the physical layer.">phy</a>-&gt;<a class="code" href="a00134.html#a00dd43576b4da205117d53bd3baadc71" title="Returns the current state the radio is in. See RadioState for possible values.">getRadioState</a>() &lt;&lt; endl;
    }

    <span class="keywordflow">if</span>(<a class="code" href="a00069.html#af06855c96a26dbe77937062bead7f82c" title="Multi-purpose message.">minorMsg</a>-&gt;isScheduled()){
    cancelEvent( <a class="code" href="a00069.html#af06855c96a26dbe77937062bead7f82c" title="Multi-purpose message.">minorMsg</a> );
    <a class="code" href="a00069.html#aa78817d8e3bbf7850e5d84a6377ea907" title="kepp track of MAC state">macState</a>=<a class="code" href="a00069.html#aa504ef94f12cc702c82a81f5f0654913ab8f2c7ef825f0c569512139f5482e631" title="MAC accepts packets from PHY layer.">RX</a>;
  }

    <span class="keywordflow">if</span>(<a class="code" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b" title="count the number of tx attempts">txAttempts</a> &gt; <a class="code" href="a00069.html#ae3aa6dae3903cabacbcafe783ef33d91" title="maximum number of transmission attempts">maxTxAttempts</a>) {
      debugEV &lt;&lt; <span class="stringliteral">&quot; drop packet &quot;</span> &lt;&lt; endl;

        cMessage *mac = <a class="code" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3" title="Encapsulates the NetwPkt into the MacPkt and sets the parameters.">encapsMsg</a>(<a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.front());
        mac-&gt;setName(<span class="stringliteral">&quot;MAC ERROR&quot;</span>);
        mac-&gt;setKind(<a class="code" href="a00026.html#a49e0e548a6c20d002bd67afa7b76c483adebf9c77bbe6f19772866cccbef0fe4b">PACKET_DROPPED</a>);
        <a class="code" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b" title="count the number of tx attempts">txAttempts</a> = 0;
        <a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.pop_front();
        <a class="code" href="a00025.html#aa1190a06fb4dfb15d8ff001468335dc8" title="Sends a control message to an upper layer.">sendControlUp</a>(mac);

        <span class="comment">//TODO: send packet drop bb info</span>
        <span class="comment">//droppedPacket.setReason(DroppedPacket::CHANNEL);</span>
        <span class="comment">//emit(catDroppedPacket, &amp;droppedPacket);</span>
    }

    <span class="keywordflow">if</span>(<a class="code" href="a00069.html#a9869bd7667eacdb3a9c5f8ecb0c3ed19" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>.size() != 0) {
      debugEV &lt;&lt; <span class="stringliteral">&quot; schedule backoff &quot;</span> &lt;&lt; endl;

        <span class="keywordtype">double</span> slots = intrand(<a class="code" href="a00069.html#a8ec2aea0983e2149d3c7d1c06637dd70" title="initial contention window size">initialCW</a> + <a class="code" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b" title="count the number of tx attempts">txAttempts</a>) + 1.0 + dblrand();
        <span class="keywordtype">double</span> time = slots * <a class="code" href="a00069.html#a420bec99b62f029c75996930bc5cb56f" title="Duration of a slot.">slotDuration</a>;

        <a class="code" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b" title="count the number of tx attempts">txAttempts</a>++;
        debugEV &lt;&lt; <span class="stringliteral">&quot; attempts so far: &quot;</span> &lt;&lt; <a class="code" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b" title="count the number of tx attempts">txAttempts</a>  &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; endl;

    <a class="code" href="a00069.html#ae768a2dadff7e2e41a5ecae37bcedc2d" title="Counts the total number of backoffs.">nbBackoffs</a> = <a class="code" href="a00069.html#ae768a2dadff7e2e41a5ecae37bcedc2d" title="Counts the total number of backoffs.">nbBackoffs</a> + 1;
    <a class="code" href="a00069.html#ace6a061501b4d12d2380a458ea253ef5" title="Counts the total time spent in backoff.">backoffValues</a> = <a class="code" href="a00069.html#ace6a061501b4d12d2380a458ea253ef5" title="Counts the total time spent in backoff.">backoffValues</a> + time;

        scheduleAt(simTime() + time, <a class="code" href="a00069.html#a946e29bb8fead33566797a7062649a1e" title="Timer for backoff (non-persistent CSMA)">backoffTimer</a>);
    }

}
</pre></div>
</div>
</div>
<hr/><h2>Member Data Documentation</h2>
<a class="anchor" id="a5a0fde63ac12cccfdb98bfe6314ce46d"></a><!-- doxytag: member="CSMAMacLayer::difs" ref="a5a0fde63ac12cccfdb98bfe6314ce46d" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">double <a class="el" href="a00069.html#a5a0fde63ac12cccfdb98bfe6314ce46d">CSMAMacLayer::difs</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Maximum time between a packet and its ACK. </p>
<p>Usually this is slightly more then the tx-rx turnaround time The channel should stay clear within this period of time. </p>

<p>Referenced by <a class="el" href="a00069.html#a254a29c1cc1f0292039d57c1d189cda3">handleSelfMsg()</a>.</p>

</div>
</div>
<a class="anchor" id="ae3aa6dae3903cabacbcafe783ef33d91"></a><!-- doxytag: member="CSMAMacLayer::maxTxAttempts" ref="ae3aa6dae3903cabacbcafe783ef33d91" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned <a class="el" href="a00069.html#ae3aa6dae3903cabacbcafe783ef33d91">CSMAMacLayer::maxTxAttempts</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>maximum number of transmission attempts </p>
<p>The packet is discarded when this number is reached. </p>

<p>Referenced by <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>.</p>

</div>
</div>
<a class="anchor" id="af06855c96a26dbe77937062bead7f82c"></a><!-- doxytag: member="CSMAMacLayer::minorMsg" ref="af06855c96a26dbe77937062bead7f82c" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">cMessage* <a class="el" href="a00069.html#af06855c96a26dbe77937062bead7f82c">CSMAMacLayer::minorMsg</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Multi-purpose message. </p>
<p>Keeps track of things like minimum time of clear channel (important for atomic acks) and race condition avoidance. </p>

<p>Referenced by <a class="el" href="a00069.html#a254a29c1cc1f0292039d57c1d189cda3">handleSelfMsg()</a>, and <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>.</p>

</div>
</div>
<a class="anchor" id="a420bec99b62f029c75996930bc5cb56f"></a><!-- doxytag: member="CSMAMacLayer::slotDuration" ref="a420bec99b62f029c75996930bc5cb56f" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">double <a class="el" href="a00069.html#a420bec99b62f029c75996930bc5cb56f">CSMAMacLayer::slotDuration</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Duration of a slot. </p>
<p>This duration can be a mini-slot (that is an RX-TX-turnaround time) but in general it should be the time it takes to send a packet plus some guard times (RX-TX-turnaround + a minimum inter-packet space). </p>

<p>Referenced by <a class="el" href="a00069.html#a89de5fd0b7f0d1420c1d4e9118c00ef3">encapsMsg()</a>, and <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>.</p>

</div>
</div>
<a class="anchor" id="a6c9b1b0f5eeb45db611633ca986f537b"></a><!-- doxytag: member="CSMAMacLayer::txAttempts" ref="a6c9b1b0f5eeb45db611633ca986f537b" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned <a class="el" href="a00069.html#a6c9b1b0f5eeb45db611633ca986f537b">CSMAMacLayer::txAttempts</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>count the number of tx attempts </p>
<p>This holds the number of transmission attempts, since no Acks are used this is the way how we can empty our queue even with overloaded channels. </p>

<p>Referenced by <a class="el" href="a00069.html#a2eb12cedf0b4b5e6fda8bd6666186cb6">handleLowerControl()</a>, and <a class="el" href="a00069.html#aa4ace66cbd53164dc27f4fba70dd60b4">scheduleBackoff()</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/mac/<a class="el" href="a00430_source.html">CSMAMacLayer.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/mac/CSMAMacLayer.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00069.html">CSMAMacLayer</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:31 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
